package status;

public class TestStop implements Runnable{
    private boolean flag=true;
    public void stop(){
        this.flag = false;
    }

    @Override
    public void run() {
        int i=0;
        while (flag){
                System.out.println("正在执行run"+i++);
        }
    }

    public static void main(String[] args) {
        TestStop testStop = new TestStop();
        new Thread(testStop).start();

        for (int i = 0; i < 50; i++) {
            System.out.println("正在执行==>main"+i);
            if (i == 20) {
                testStop.stop();
                System.out.println("run停止");
            }
        }
    }
}
